<html>
<head><meta charset="utf-8"><title>why are `Some` and `None` language items? · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/why.20are.20.60Some.60.20and.20.60None.60.20language.20items.3F.html">why are `Some` and `None` language items?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="219275374"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/why%20are%20%60Some%60%20and%20%60None%60%20language%20items%3F/near/219275374" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/why.20are.20.60Some.60.20and.20.60None.60.20language.20items.3F.html#219275374">(Dec 08 2020 at 23:03)</a>:</h4>
<p>Why are <code>Some</code> and <code>None</code> language items? For reference, <code>Option</code> is not (though it is a diagnostics item, which makes sense).</p>



<a name="219279993"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/why%20are%20%60Some%60%20and%20%60None%60%20language%20items%3F/near/219279993" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/why.20are.20.60Some.60.20and.20.60None.60.20language.20items.3F.html#219279993">(Dec 08 2020 at 23:46)</a>:</h4>
<p>You can check where they're used, which should explain it</p>



<a name="219280615"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/why%20are%20%60Some%60%20and%20%60None%60%20language%20items%3F/near/219280615" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/why.20are.20.60Some.60.20and.20.60None.60.20language.20items.3F.html#219280615">(Dec 08 2020 at 23:54)</a>:</h4>
<p><span class="user-mention" data-user-id="307537">@Camelid</span> <code>for</code> turns into <code>while let Some(x)</code>, which is probably why <code>Some</code>, at least.</p>



<a name="219285957"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/why%20are%20%60Some%60%20and%20%60None%60%20language%20items%3F/near/219285957" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/why.20are.20.60Some.60.20and.20.60None.60.20language.20items.3F.html#219285957">(Dec 09 2020 at 01:02)</a>:</h4>
<p>Ah, that makes sense.</p>



<a name="219286075"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/why%20are%20%60Some%60%20and%20%60None%60%20language%20items%3F/near/219286075" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/why.20are.20.60Some.60.20and.20.60None.60.20language.20items.3F.html#219286075">(Dec 09 2020 at 01:04)</a>:</h4>
<p>Wait: actually I read recently (in a rustc-dev-guide PR) that some things, e.g. <code>Iterator</code>, have hardcoded paths by the compiler since they are used in desugaring, before lang items are resolved. So if that's correct, it doesn't seem like your example would explain it.</p>



<a name="219286210"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/why%20are%20%60Some%60%20and%20%60None%60%20language%20items%3F/near/219286210" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/why.20are.20.60Some.60.20and.20.60None.60.20language.20items.3F.html#219286210">(Dec 09 2020 at 01:06)</a>:</h4>
<p>Nope, I guess I'm wrong :)</p>
<p>This:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">for</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="mi">0</span><span class="o">..</span><span class="mi">5</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>Desugars into this:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="cp">#[prelude_import]</span><span class="w"></span>
<span class="k">use</span><span class="w"> </span>::<span class="n">std</span>::<span class="n">prelude</span>::<span class="n">v1</span>::<span class="o">*</span><span class="p">;</span><span class="w"></span>
<span class="cp">#[macro_use]</span><span class="w"></span>
<span class="k">extern</span><span class="w"> </span><span class="k">crate</span><span class="w"> </span><span class="n">std</span><span class="p">;</span><span class="w"></span>
<span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">              </span><span class="p">{</span><span class="w"></span>
<span class="w">                  </span><span class="kd">let</span><span class="w"> </span><span class="n">_t</span><span class="w"> </span><span class="o">=</span><span class="w"></span>
<span class="w">                      </span><span class="k">match</span><span class="w"> </span><span class="cp">#[lang = </span><span class="s">"into_iter"</span><span class="cp">]</span><span class="p">(</span><span class="cp">#[lang = </span><span class="s">"Range"</span><span class="cp">]</span><span class="p">{</span><span class="n">start</span>: <span class="mi">0</span><span class="p">,</span><span class="w"></span>
<span class="w">                                                                    </span><span class="n">end</span>: <span class="mi">5</span><span class="p">,})</span><span class="w"></span>
<span class="w">                          </span><span class="p">{</span><span class="w"></span>
<span class="w">                          </span><span class="k">mut</span><span class="w"> </span><span class="n">iter</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"></span>
<span class="w">                          </span><span class="k">loop</span><span class="w">  </span><span class="p">{</span><span class="w"></span>
<span class="w">                              </span><span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">__next</span><span class="p">;</span><span class="w"></span>
<span class="w">                              </span><span class="k">match</span><span class="w"> </span><span class="cp">#[lang = </span><span class="s">"next"</span><span class="cp">]</span><span class="p">(</span><span class="o">&amp;</span><span class="k">mut</span><span class="w"> </span><span class="n">iter</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">                                  </span><span class="cp">#[lang = </span><span class="s">"Some"</span><span class="cp">]</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="mi">0</span>: <span class="nc">val</span><span class="w"> </span><span class="p">}</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="n">__next</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">val</span><span class="p">,</span><span class="w"></span>
<span class="w">                                  </span><span class="cp">#[lang = </span><span class="s">"None"</span><span class="cp">]</span><span class="w"> </span><span class="p">{</span><span class="w">  </span><span class="p">}</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="k">break</span><span class="w"> </span><span class="p">,</span><span class="w"></span>
<span class="w">                              </span><span class="p">}</span><span class="w"></span>
<span class="w">                              </span><span class="kd">let</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">__next</span><span class="p">;</span><span class="w"></span>
<span class="w">                              </span><span class="p">{</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="w">                          </span><span class="p">},</span><span class="w"></span>
<span class="w">                      </span><span class="p">};</span><span class="w"></span>
<span class="w">                  </span><span class="n">_t</span><span class="w"></span>
<span class="w">              </span><span class="p">}</span><span class="w"></span>
<span class="w">          </span><span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>so you're right after all.</p>



<a name="219288438"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/why%20are%20%60Some%60%20and%20%60None%60%20language%20items%3F/near/219288438" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/why.20are.20.60Some.60.20and.20.60None.60.20language.20items.3F.html#219288438">(Dec 09 2020 at 01:39)</a>:</h4>
<p><span class="user-mention silent" data-user-id="307537">Camelid</span> <a href="#narrow/stream/131828-t-compiler/topic/why.20are.20.60Some.60.20and.20.60None.60.20language.20items.3F/near/219286075">said</a>:</p>
<blockquote>
<p>Wait: actually I read recently (in a rustc-dev-guide PR) that some things, e.g. <code>Iterator</code>, have hardcoded paths by the compiler since they are used in desugaring, before lang items are resolved. So if that's correct, it doesn't seem like your example would explain it.</p>
</blockquote>
<p>I think that PR might be out of date</p>



<a name="219289765"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/why%20are%20%60Some%60%20and%20%60None%60%20language%20items%3F/near/219289765" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/why.20are.20.60Some.60.20and.20.60None.60.20language.20items.3F.html#219289765">(Dec 09 2020 at 02:02)</a>:</h4>
<p><span class="user-mention silent" data-user-id="307537">Camelid</span> <a href="#narrow/stream/131828-t-compiler/topic/why.20are.20.60Some.60.20and.20.60None.60.20language.20items.3F/near/219286075">said</a>:</p>
<blockquote>
<p>Wait: actually I read recently (in a rustc-dev-guide PR) that some things, e.g. <code>Iterator</code>, have hardcoded paths by the compiler since they are used in desugaring, before lang items are resolved. So if that's correct, it doesn't seem like your example would explain it.</p>
</blockquote>
<p>That definitely used to be the case, but the example I knew of looks like it's been updated to use lang items (&lt;<a href="https://github.com/rust-lang/rust/blob/bda05cc471f8cf4a3c45f587f87d7b01a8343c3c/compiler/rustc_ast_lowering/src/expr.rs#L453-L505">https://github.com/rust-lang/rust/blob/bda05cc471f8cf4a3c45f587f87d7b01a8343c3c/compiler/rustc_ast_lowering/src/expr.rs#L453-L505</a>&gt;), so maybe that doesn't happen any more.</p>



<a name="219297731"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/why%20are%20%60Some%60%20and%20%60None%60%20language%20items%3F/near/219297731" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/why.20are.20.60Some.60.20and.20.60None.60.20language.20items.3F.html#219297731">(Dec 09 2020 at 04:50)</a>:</h4>
<p><span class="user-mention silent" data-user-id="232545">Joshua Nelson</span> <a href="#narrow/stream/131828-t-compiler/topic/why.20are.20.60Some.60.20and.20.60None.60.20language.20items.3F/near/219288438">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="307537">Camelid</span> <a href="#narrow/stream/131828-t-compiler/topic/why.20are.20.60Some.60.20and.20.60None.60.20language.20items.3F/near/219286075">said</a>:</p>
<blockquote>
<p>Wait: actually I read recently (in a rustc-dev-guide PR) that some things, e.g. <code>Iterator</code>, have hardcoded paths by the compiler since they are used in desugaring, before lang items are resolved. So if that's correct, it doesn't seem like your example would explain it.</p>
</blockquote>
<p>I think that PR might be out of date</p>
</blockquote>
<p><span class="user-mention" data-user-id="232545">@Joshua Nelson</span> I left a comment on that PR (<a href="https://github.com/rust-lang/rustc-dev-guide/issues/978">rustc-dev-guide#978</a>)</p>



<a name="219325751"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/why%20are%20%60Some%60%20and%20%60None%60%20language%20items%3F/near/219325751" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/why.20are.20.60Some.60.20and.20.60None.60.20language.20items.3F.html#219325751">(Dec 09 2020 at 11:48)</a>:</h4>
<p>Thanks!</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>